<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 20.05.2015
 * Time: 15:31
 */

namespace SitemapGenerator;


class SitemapIndex {
	protected $generators = null;

	public function __construct()
	{
		$generatorsTypes = \SitemapGeneratorConfig::get('types');
		$generatorsInfo = \SitemapGeneratorConfig::get('index');

		if ($generatorsInfo == null) {
			throw new \Exception("Generators info doesn't exists in config");
		}

		if ($generatorsTypes == null) {
			throw new \Exception("Generators types info doesn't exists in config");
		}

		foreach ($generatorsInfo as $generatorName => $generatorInfo) {
			$generatorTypeInfo =  isset($generatorsTypes[$generatorInfo['type']]) ?
				$generatorsTypes[$generatorInfo['type']] : null;

			if (!$generatorTypeInfo) {
				continue;
			}

			$this->generators[$generatorName] = static::buildObject($generatorTypeInfo);
		}
	}

	public static function buildObject($buildData)
	{
		$className = $buildData['class'];
		$classParams = $buildData['params'];

		return new $className($classParams);
	}
} 